package com.eastseeway.radioproject.base;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;

public class BaseRepository {
    protected final ScheduledExecutorService executorService;

    public BaseRepository() {
        executorService = Executors.newScheduledThreadPool(3);
    }

    public Boolean isNetConnected(Context context) {
        ConnectivityManager cm = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);

        if (cm == null) return false;

        Network activeNetwork = cm.getActiveNetwork();
        if (activeNetwork == null) return false;

        NetworkCapabilities capabilities = cm.getNetworkCapabilities(activeNetwork);
        if (capabilities == null) return false;

        if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
            return true;
        } else return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
    }
}
